local fk__zhice = fk.CreateSkill {

  name = "fk__zhice",

  tags = {  },

}

local U = require "packages/utility/utility"


fk__zhice:addEffect(fk.AfterCardsMove, {
  name = "fk__zhice",
  events = {fk.AfterCardsMove},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(fk__zhice.name) and player ~= player.room.current then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand then
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return p:getHandcardNum() <= player:getHandcardNum()
    and not p:isNude() end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#fk__zhice-choose", fk__zhice.name, true)
    if #tos > 0 then
      event:setCostData(self, tos[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    local cards = room:askForDiscard(to, 1, 9999, true, fk__zhice.name, true, ".|.|.|.|.|equip", "#fk__zhice-card")
    if not to.dead and #cards > 0 then
      to:drawCards(#cards, fk__zhice.name)
    end
  end,
})

return fk__zhice